package br.com.news.database.services;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import br.com.news.database.daos.interfaces.IEnqueteDao;
import br.com.news.database.entities.EnqueteEntity;
import br.com.news.database.exception.DataBaseException;
import br.com.news.database.utils.GenericService;
import br.com.news.database.utils.interfaces.IGenericDao;
import br.com.news.utils.database.beans.EnqueteBean;
import br.com.news.utils.database.exception.DataBaseServiceException;
import br.com.news.utils.database.interfaces.IEnqueteServiceDb;

@Named
public class EnqueteServiceDb extends GenericService<EnqueteBean, EnqueteEntity, Long> implements IEnqueteServiceDb{

	@Inject
	private IEnqueteDao enqueteDao;
	
	@Override
	protected IGenericDao<EnqueteEntity, Long> getConcreteDao() {
		return this.enqueteDao;
	}

	@Override
	public Long save(EnqueteBean enqueteBean) throws DataBaseServiceException {
		try {
			return enqueteDao.save(parserBean(enqueteBean));
		} catch (DataBaseException e) {
			throw new DataBaseServiceException("Erro ao tentar salvar a entidade",e);
		}
	}
	
	@Override
	public List<EnqueteBean> findByQuestion(EnqueteBean questao) {
		return parserEntity(enqueteDao.findByQuestion(parserBean(questao)));
	}

	@Override
	public List<EnqueteBean> findPollByStatus(boolean status) throws DataBaseServiceException {
		try {
			return parserEntity(this.enqueteDao.findPollByStatus(status));
		} catch (DataBaseException e) {
			throw new DataBaseServiceException(e);
		}
	}
	
	@Override
	public List<EnqueteBean> getLastPool() throws DataBaseServiceException {
		try {
			return parserEntity(this.enqueteDao.getLastPoll());
		} catch (DataBaseException e) {
			throw new DataBaseServiceException("Erro ao tentar salvar a entidade",e);
		}
	}

}
